package com.btpn.custody.web.m004.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import com.opensymphony.xwork2.validator.annotations.ValidatorType;

@ParentPackage(value="custody")
@Results({
	@Result(name="input", location="t_dataMigration_form")
})
@Validations(
		requiredStrings = {
			@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "fromDate", message = "Pick from date"),
			@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "toDate", message = "Pick to date")
		}
)
public class DataMigrationAction extends ActionSupport {

	/*=============================================== C O N S T A N T =========================================*/
	private static final long serialVersionUID = -4610818383900000505L;

//	private static SimpleDateFormat format = new SimpleDateFormat(Constant.FORMAT_PRESENTATION);
	
//	private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
	
	/*=============================================== M E M B E R =============================================*/	
	@Autowired
//	private DailyTask dailyTask;
	
	private String fromDate;
	private String toDate;
		
	/*=============================================== B E H A V I O R =========================================*/
	@SkipValidation
	@Action(value = "/dataMigration-form", results = { @Result(name="success", location="t_dataMigration_form") })
	public String execute() throws Exception {

		setFromDate(null);
	    setToDate(null);
	    
		return SUCCESS;
	}
	
	@Action(value = "/migrateData", results = { 
			@Result(name="success", type="redirectAction", params = {"actionName", "checklist"} )
	})
	public String migrateData() throws Exception {
		
		// get completeDatas in date range
//		Date from = format.parse(fromDate);
//		Date to = format.parse(toDate);
		
//		dailyTask.manualInitial(from, to);
		
		return SUCCESS;
	}
	
	/*=============================================== G E T T E R   &   S E T T E R ===========================*/
	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
}
